/**
 * Copyright &copy; 2012-2016 <a href="https://github.com/thinkgem/jeesite">JeeSite</a> All rights reserved.
 */
package com.better.backend.mqReceiverService.calType.model;

import com.better.consist.CalTypeEnum;

import java.math.BigDecimal;

/**
 * 计算平均分工具类
 *
 * @author
 * @version 2017-09-18
 */
public class AvgUtilModel {
    private Double totalScore = new Double(0);  //总分
    private int num;    //总人数
    private String subjectName; //科目名称
    private String subjectId;

    public String getSubjectName() {
        return subjectName;
    }

    public void setSubjectName(String subjectName) {
        this.subjectName = subjectName;
    }

    public String getSubjectId() {
        return subjectId;
    }

    public void setSubjectId(String subjectId) {
        this.subjectId = subjectId;
    }

    public Double getTotalScore() {
        return totalScore;
    }

    public void setTotalScore(Double totalScore) {
        this.totalScore = totalScore;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }
    public Double calAvg(CalTypeModel calTypeModel){
        BigDecimal reAvg = new BigDecimal(0);
        BigDecimal to = new BigDecimal(this.totalScore);
        if(CalTypeEnum.smallNum_one.equals(calTypeModel.getSmallNum())){
            reAvg = to.divide(new BigDecimal(this.num),2,BigDecimal.ROUND_HALF_UP);
        }
        else if(CalTypeEnum.smallNum_two.equals(calTypeModel.getSmallNum())){
            reAvg = to.divide(new BigDecimal(this.num),0,BigDecimal.ROUND_HALF_UP);
        }
        else if(CalTypeEnum.smallNum_three.equals(calTypeModel.getSmallNum())){
            reAvg = to.divide(new BigDecimal(this.num),2,BigDecimal.ROUND_UP);
        }
        else{
            reAvg = to.divide(new BigDecimal(this.num),0,BigDecimal.ROUND_UP);
        }
        return reAvg.doubleValue();
    }
}